package com.bbcare.comm;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;



public class ExceptionHandler
  implements HandlerExceptionResolver
{
  public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
  {
   ModelAndView mv = new ModelAndView();
   FastJsonJsonView view = new FastJsonJsonView();
   Map<String, Object> attributes = new HashMap();
   attributes.put("success", Boolean.valueOf(false));
   attributes.put("code", Integer.valueOf(2000));
   String msg = ex.getMessage();
   if (msg == null) { ex.printStackTrace();
    }
    attributes.put("msg", msg);
    view.setAttributesMap(attributes);
    mv.setView(view);
    return mv;
  }
}


